//
//  JWAlarmClockSettingViewController.m
//  SiqiCalendar
//
//  Created by sunjiawen on 2018/4/2.
//  Copyright © 2018年 sjw. All rights reserved.
//

#import "JWAlarmClockSettingViewController.h"
#import "JWAlarmSettingItem.h"
@interface JWAlarmClockSettingViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UIDatePicker   *timePicker;
@property (weak, nonatomic) IBOutlet UITableView    *tableView;
@property (strong, nonatomic) NSMutableArray        *dataSource;
@end

@implementation JWAlarmClockSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupData];
    
    [self setupUI];
}

- (void)setupData {
    JWAlarmSettingItem *calendar = [JWAlarmSettingItem itemWithTitle:@"日历" detail:@"默认"];
    JWAlarmSettingItem *repeat = [JWAlarmSettingItem itemWithTitle:@"重复" detail:@"无"];
    JWAlarmSettingItem *remark = [JWAlarmSettingItem itemWithTitle:@"标签" detail:@"无"];
    JWAlarmSettingItem *sound = [JWAlarmSettingItem itemWithTitle:@"铃声" detail:@"无"];
    JWAlarmSettingItem *snoozetime = [JWAlarmSettingItem itemWithTitle:@"贪睡" detail:@"无"];
    
    calendar.block = ^{
        DLog(@"点击calendar了");
    };
    
    repeat.block = ^{
        DLog(@"点击repeat了");
    };
    
    remark.block = ^{
        DLog(@"点击remark了");
    };
    
    sound.block = ^{
        DLog(@"点击sound了");
    };
    
    snoozetime.block = ^{
        DLog(@"点击snoozetime了");
    };
    
    [self.dataSource addObjectsFromArray:@[calendar,repeat,remark,sound,snoozetime]];
    [self.tableView reloadData];
}

- (void)setupUI {
    self.title = self.editing ? @"编辑闹钟" : @"新建闹钟";
    
    [self.timePicker setValue:[UIColor whiteColor] forKey:@"textColor"];
    
    self.tableView.tableFooterView = [UIView new];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"存储" style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonItemAction:)];
}

#pragma mark - Actions
- (IBAction)datePickerValueChanged:(UIDatePicker *)sender {
    DLog(@"%@",sender.date);
}

- (void)rightBarButtonItemAction:(UIBarButtonItem *)sender {
    DLog(@"存储");
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"JWAlarmSettingCellId"];
    JWAlarmSettingItem *item = self.dataSource[indexPath.row];
    cell.textLabel.text = item.title;
    cell.detailTextLabel.text = item.detail;
    return cell;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    JWAlarmSettingItem *item = self.dataSource[indexPath.row];
    if (item.block) {
        item.block();
    }
}

#pragma mark - Lazy
- (NSMutableArray *)dataSource {
    if (!_dataSource) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

@end
